package chapter13;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class ConnMySql {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        try(
            Connection connection = DriverManager.getConnection(
                    "jdbc:mysql://127.0.0.1:3306/crazy_java?serverTimezone=GMT&useSSL=true",
                    "root",
                    "Lmz8860@#$");
            Statement stmt = connection.createStatement();
            ResultSet rs = stmt.executeQuery("select s.*, teacher_name from t_student s, t_teacher t  where t.teacher_id = s.java_teacher"))
        {
            while (rs.next()) {
                System.out.println(rs.getInt(1) + "\t"
                + rs.getString(2) + "\t"
                + rs.getString(3) + "\t"
                + rs.getString(4));
            }
        }
    }
}
